package com.zhuannimei.utility;

import java.io.File;
import java.io.IOException;

import android.os.Environment;

public class FileUtil {

	private static final String TAG = "FileUtil";
	public static final String SDCARD_CACHE_USCHOOL_PATH = Environment
			.getExternalStorageDirectory().getPath() + "/.znmfiles";

	/**
	 * 获取语音存储地址
	 * 
	 * @return
	 * @throws IOException
	 */
	public static File getAudioDir() throws IOException {
		File file = null;
		String sdStateString = android.os.Environment.getExternalStorageState();
		if (sdStateString.equals(android.os.Environment.MEDIA_MOUNTED)) {
			file = new File(getChatVoicePath());
			WuLog.i(TAG, file + "");
			// 保证文件存在
			if (!file.exists())
				file.mkdir();
		} else {
			throw new IOException("sdcard could not be write");
		}
		return file;
	}

	/**
	 * 返回聊天的语音聊天信息地址
	 * 
	 * @param userId
	 *            接收人的id
	 * @return
	 */
	public static String getChatVoicePath() {
		String target = getCacheUschoolPath() + "/chatVoices/";
		File file = new File(target);
		if (!file.exists()) {
			file.mkdirs();
		}
		return target;
	}

	/**
	 * 获取学生圈根目录
	 * 
	 * @return
	 */
	public static String getCacheUschoolPath() {
		File file = new File(SDCARD_CACHE_USCHOOL_PATH);
		if (!file.exists()) {
			file.mkdirs();
		}
		return SDCARD_CACHE_USCHOOL_PATH;
	}
}
